package com.meixiang.activity.account.managers.myPurse;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import com.google.gson.Gson;
import com.lzy.okhttputils.model.HttpParams;
import com.meixiang.R;
import com.meixiang.entity.account.CashLogIndexInfos;
import com.meixiang.global.Config;
import com.meixiang.http.HttpCallBack;
import com.meixiang.http.HttpUtils;
import com.meixiang.main.BaseActivity;
import com.meixiang.tool.Tool;
import com.meixiang.util.AbToastUtil;
import com.meixiang.view.TitleView;

import org.json.JSONObject;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * 收支详情
 *
 * @author zys
 */
public class IncomeDetailsActivity extends BaseActivity {

    @Bind(R.id.title)
    TitleView title;
    @Bind(R.id.tv_entry_money)
    TextView tvEntryMoney;
    @Bind(R.id.tv_icome_details_type)
    TextView tvIcomeDetailsType;
    @Bind(R.id.tv_icome_details_time)
    TextView tvIcomeDetailsTime;
    @Bind(R.id.tv_income_details_transaction_number)
    TextView tvIncomeDetailsTransactionNumber;
    @Bind(R.id.tv_income_details_account_balance)
    TextView tvIncomeDetailsAccountBalance;

    private String  pdrId;
    private  String   pdrSn;
    private Activity mActivity;
    private  CashLogIndexInfos infos;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        setContentView(R.layout.activity_income_details);
        mActivity=IncomeDetailsActivity.this;
        ButterKnife.bind(this);
        super.onCreate(savedInstanceState);

    }

    @Override
    protected void initTitle() {
        title.setTitle("收支详情");
        title.setLeftImageButton(R.mipmap.back);
        title.showLeftButton(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
    }

    @Override
    protected void initView() {
        if (!getIntent().getStringExtra("pdrId").equals("")||!getIntent().getStringExtra("pdrSn").equals("")){
            pdrId=getIntent().getStringExtra("pdrId");
            pdrSn=getIntent().getStringExtra("pdrSn");
        }
    }

    @Override
    protected void setData() {
        getDatas();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        ButterKnife.unbind(this);
    }


    @Override
    public void onClick(View v) {

    }
     private  void getDatas(){
         HttpParams params=new HttpParams();
         params.put("orderId",pdrSn);
         params.put("pdrId",pdrId);
         HttpUtils.post(Config.CASHLOGDETAIL_URL, params, new HttpCallBack(mActivity) {
             @Override
             public void onSucceed(JSONObject result, String code, String message) {
                      infos=new Gson().fromJson(result.toString(), CashLogIndexInfos.class);
                 tvEntryMoney.setText(Tool.toDivAccount2(infos.getPdrAmount()));
                  tvIcomeDetailsType.setText(infos.getPdrType());
                 tvIcomeDetailsTime.setText(infos.getPdrPaymentTime());
                 tvIncomeDetailsTransactionNumber.setText(infos.getPdrSn());
                 tvIncomeDetailsAccountBalance.setText(Tool.toDivAccount2(infos.getAvailableBalance()));
             }

             @Override
             public void onError(String code, String message) {
                 AbToastUtil.showToast(mActivity,message);
             }
         });



     }


}
